package leetcode; /**
 * description:
 * author:zt
 * date:2021-08-28
 */

/**
 * 给两个整数数组 A 和 B ，返回两个数组中公共的、长度最长的子数组的长度。
 */
public class leetcode718 {
    public static int findLength(int[] nums1, int[] nums2) {
        int len1 = nums1.length, len2 = nums2.length;
        int res = Integer.MIN_VALUE;
        int[][] dp = new int[len1][len2];
        for (int i = 0; i < len1; i++) {
            for (int j = 0; j < len2; j++) {
                if (nums1[i]==nums2[j]){
                    if (i==0 || j==0) dp[i][j] = 1;
                    else dp[i][j] = dp[i-1][j-1]+1;
                    res = Math.max(res,dp[i][j]);
                }
            }
        }
        return dp[len1-1][len2-1];
    }
}
